/**
 * @ClassName StringDemo04
 * @Description 转换功能的方法
 * @Author Li
 * @Date 2022/8/1 8:54
 * @ModifyDate 2022/8/1 8:54
 * @Version 1.0
 */
public class StringDemo04 {
    public static void main(String[] args) {
        // 创建字符串对象
        String str = "Hello World";

        // toCharArray()：将此字符串转换为新的字符数组
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }
        System.out.println("===============");

        byte[] bytes = str.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            System.out.println(bytes[i]);
        }
        System.out.println("===============");

        // replace(CharSequence target, CharSequence replacement)：
        // 将与target匹配的字符串使用replacement字符串替换
        String str1 = str.replace("W", "w");
        System.out.println(str1); // Hello world
    }
}
